<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>团队管理员管理</title>

    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- 自定义样式 -->
    <style>
        body {
            background-color: #f4f7fc;
            font-family: Arial, sans-serif;
            display: flex;
            min-height: 100vh;
            margin: 0;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background-color: #007bff;
            color: white;
            height: 100vh;
            position: fixed;
            top: 0;
            left: 0;
            padding-top: 20px;
            box-shadow: 2px 0px 5px rgba(0, 0, 0, 0.1);
        }

        .sidebar h2 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 20px;
        }

        .sidebar a {
            display: block;
            padding: 12px;
            color: white;
            text-decoration: none;
            font-size: 16px;
        }

        .sidebar a:hover {
            background-color: #0056b3;
        }

        /* 页面主内容部分 */
        .main-content {
            margin-left: 250px; /* 留出侧边栏空间 */
            padding: 20px;
            flex-grow: 1;
        }

        .container {
            max-width: 1100px;
            margin: 30px auto;
        }

        h1 {
            text-align: center;
            margin-top: 20px;
            color: #343a40;
        }

        .alert-message {
            margin: 20px 0;
        }

        .table th,
        .table td {
            text-align: center;
            vertical-align: middle;
            padding: 0.75rem;
            font-size: 0.9rem;
        }
        .table th, .table td {
            min-width: 120px;
        }
        .table th {
            background-color: #007bff;
            color: white;
            position: sticky;
            top: 0;
            z-index: 1;
        }

        .table td {
            background-color: #ffffff;
        }

        .table-striped tbody tr:nth-of-type(odd) {
            background-color: #f9f9f9;
        }

        .table-hover tbody tr:hover {
            background-color: #e9ecef;
        }

        .btn-custom {
            margin: 5px;
            background-color: #007bff;
            color: white;
        }

        .btn-custom:hover {
            background-color: #0056b3;
            color: white;
        }

        .back-link {
            display: block;
            margin-top: 20px;
            text-align: center;
            font-size: 1.1rem;
            color: #007bff;
        }

        .back-link:hover {
            color: #0056b3;
        }

        .action-links a {
            margin: 0 5px;
            white-space: nowrap;
        }

        .action-links a:hover {
            text-decoration: underline;
        }

        /* 调整按钮大小 */
        .btn-sm {
            padding: 0.25rem 0.5rem;
            font-size: 0.8rem;
            line-height: 1.5;
            border-radius: 0.2rem;
        }

        /* 工具提示样式 */
        .tooltip-inner {
            max-width: 300px;
            text-align: left;
        }
    </style>
</head>

<body>
<!-- 侧边栏 -->
<div class="sidebar">
    <h2>超级管理员控制台</h2>
    <a href="/superAdmin/achievementReview">科研成果审核</a>
    <a href="/superAdmin/users">用户管理</a>
    <a href="/superAdmin/permissions/management">权限管理</a>
    <a href="/superAdmin/articleReview">文章审核</a>
    <a href="/logout">退出登录</a>
</div>

<!-- 页面主内容 -->
<div class="main-content">
    <div class="container">
        <h1>团队管理员列表</h1>

        <!-- 显示成功或错误消息 -->
        <c:if test="${not empty message}">
            <div class="alert alert-success alert-message">${message}</div>
        </c:if>

        <c:if test="${not empty error}">
            <div class="alert alert-danger alert-message">${error}</div>
        </c:if>

        <!-- 管理员列表表格 -->
        <div class="table-responsive">
            <table class="table table-striped table-hover table-sm">
                <thead>
                <tr>
                    <th>用户名</th>
                    <th>用户姓名</th>
                    <th>邮箱</th>
                    <th>角色类型</th>
                    <th>研究方向</th>
                    <th>团队</th>
                    <th class="d-none d-md-table-cell">联系电话</th>
                    <th class="d-none d-lg-table-cell">学术背景</th>
                    <th class="d-none d-lg-table-cell">科研成果</th>
                    <th>职务</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="admin" items="${admins}">
                    <tr>
                        <td>${admin.nickname}</td>
                        <td>${admin.name}</td>
                        <td>${admin.email}</td>
                        <td>
                            <c:choose>
                                <c:when test="${admin.roleType == 0}">超级管理员</c:when>
                                <c:when test="${admin.roleType == 1}">团队管理员</c:when>
                                <c:when test="${admin.roleType == 2}">团队成员</c:when>
                                <c:otherwise>普通用户</c:otherwise>
                            </c:choose>
                        </td>
                        <td>${admin.researchDirection}</td>
                        <td>
                            <c:forEach var="team" items="${teams}">
                                <c:if test="${admin.teamId == team.teamId}">
                                    ${team.teamName}
                                </c:if>
                            </c:forEach>
                        </td>
                        <td class="d-none d-md-table-cell">${admin.phoneNumber}</td>
                        <td class="d-none d-lg-table-cell">
                                    <span data-bs-toggle="tooltip" data-bs-placement="top" title="${admin.academicBackground}">
                                            ${fn:length(admin.academicBackground) > 15 ? fn:substring(admin.academicBackground, 0, 15) + "..." : admin.academicBackground}
                                    </span>
                        </td>
                        <td class="d-none d-lg-table-cell">
                                    <span data-bs-toggle="tooltip" data-bs-placement="top" title="${admin.researchAchievements}">
                                            ${fn:length(admin.researchAchievements) > 15 ? fn:substring(admin.researchAchievements, 0, 15) + "..." : admin.researchAchievements}
                                    </span>
                        </td>
                        <td>${admin.jobTitle}</td>
                        <td>
                            <c:choose>
                                <c:when test="${admin.status == 1}">启用</c:when>
                                <c:otherwise>禁用</c:otherwise>
                            </c:choose>
                        </td>
                        <td class="action-links">
                            <a href="<c:url value='/superAdmin/users/edit/${admin.userId}' />" class="btn btn-warning btn-sm">编辑</a>
                            <a href="<c:url value='/superAdmin/users/delete/${admin.userId}' />" class="btn btn-danger btn-sm"
                               onclick="return confirm('确认删除该管理员吗？')">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>

        <!-- 创建新管理员的链接 -->
        <div class="text-center mt-4">
            <a href="<c:url value='/superAdmin/users/create' />" class="btn btn-success btn-lg">创建新管理员</a>
        </div>

    </div>
</div>

<!-- 引入Bootstrap JS 和依赖 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 初始化所有工具提示
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
    var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl)
    })
</script>
</body>

</html>
